package com.icart.controller.personController;

import com.icart.context.HttpUserContext;
import com.icart.context.storage.ContextStorage;
import com.icart.context.storage.SessionContextStorageImpl;

import com.icart.repositories.CustinfoRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

import java.util.List;


@Controller
@RequestMapping("/person")
public class MyaccountController {

    @Autowired
    HttpServletRequest request;
    @Autowired
    CustinfoRepository custinfoRepository;

    @RequestMapping("/myaccount")
    public String phoneservice(Model model) {
        ContextStorage storage=new SessionContextStorageImpl(request);
        HttpUserContext userContext=storage.getUserContext("loginuser");

        List list=custinfoRepository.createNativeQuery("select points,balance from cu_custinfo where custid="+userContext.getCustid());
       /* CuCustinfoEntity cuCustinfo=custinfoRepository.findbalance(userContext.getCustid());*/
        model.addAttribute("cuCustinfo",list.get(0));
        return "person/myaccount/myaccount";
    }

}